home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Draw / Sources / ToolFacet.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  7.1 KB  |  297 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                ToolFacet.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //    Creation Date:        3/28/94
  8. //
  9. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //========================================================================================
  12.  
  13. #ifndef TOOLFACET_H
  14. #include "ToolFacet.h"
  15. #endif
  16.  
  17. #ifndef DRAWPART_H
  18. #include "DrawPart.h"
  19. #endif
  20.  
  21. #ifndef DRAWSELECTION_H
  22. #include "DrawSelection.h"
  23. #endif
  24.  
  25. #ifndef SHAPES_H
  26. #include "Shapes.h"
  27. #endif
  28.  
  29. #ifndef DRAWFRAME_H
  30. #include "DrawFrame.h"
  31. #endif
  32.  
  33. // ----- Framework Includes -----
  34.  
  35. #ifndef FWUTIL_H
  36. #include "FWUtil.h"
  37. #endif
  38.  
  39. #ifndef FWFRMING_H
  40. #include "FWFrming.h"
  41. #endif
  42.  
  43. // ----- Graphix Includes -----
  44.  
  45. #ifndef FWINK_H
  46. #include "FWInk.h"
  47. #endif
  48.  
  49. #ifndef FWSTYLE_H
  50. #include "FWStyle.h"
  51. #endif
  52.  
  53. #ifndef FWCOLOR_H
  54. #include "FWColor.h"
  55. #endif
  56.  
  57. // ----- OpenDoc Includes -----
  58.  
  59. #ifndef _TRNSFORM_
  60. #include <Trnsform.h>
  61. #endif
  62.  
  63. // ----- Macintosh Includes -----
  64.  
  65. #ifndef __EVENTS__
  66. #include <Events.h>        // GetMouse, StillDown.
  67. #endif
  68.  
  69. #ifndef __QUICKDRAW__
  70. #include <Quickdraw.h>
  71. #endif
  72.  
  73. #ifndef __TOOLUTILS__
  74. #include <ToolUtils.h>    // HiWord etc.
  75. #endif
  76.  
  77. #ifndef __LIMITS__
  78. #include <limits.h>
  79. #endif
  80.  
  81. #ifndef __STDLIB__
  82. #include <StdLib.h>        // Abs
  83. #endif
  84.  
  85. #ifndef __DRAG__
  86. #include <Drag.h>
  87. #endif
  88.  
  89. #ifndef mathRoutinesIncludes
  90. #include <math routines.h>        // See MoveTransformBy
  91. #endif
  92.  
  93. #pragma segment drawpart
  94.  
  95. //=========================================================================
  96. // CToolFacet
  97. //=========================================================================
  98.  
  99. //------------------------------------------------------------------------------
  100. // CToolFacet::CToolFacet
  101. //------------------------------------------------------------------------------
  102.  
  103. CToolFacet::CToolFacet()
  104. {
  105. }
  106.  
  107. //------------------------------------------------------------------------------
  108. // CToolFacet::InitToolFacet
  109. //------------------------------------------------------------------------------
  110.  
  111. void CToolFacet::InitToolFacet(XMPFacet* xmpFacet, CDrawPart* drawPart)
  112. {
  113.     InitFacet(xmpFacet);
  114.     fDrawPart = drawPart;
  115.     
  116.     fRects[0].Set(ff(2), ff(2), ff(24), ff(24));
  117.     fRects[1].Set(ff(23), ff(2), ff(45), ff(24));
  118.     
  119.     fRects[2].Set(ff(2), ff(23), ff(24), ff(45));
  120.     fRects[3].Set(ff(23), ff(23), ff(45), ff(45));
  121.     
  122.     fRects[4].Set(ff(2), ff(44), ff(24), ff(66));
  123.     fRects[5].Set(ff(23), ff(44), ff(45), ff(66));
  124.  
  125.     fRects[6].Set(ff(2), ff(69), ff(17), ff(81));
  126.     fRects[7].Set(ff(16), ff(69), ff(31), ff(81));
  127.     fRects[8].Set(ff(30), ff(69), ff(45), ff(81));
  128. }
  129.  
  130. //------------------------------------------------------------------------------
  131. // CToolFacet::~CToolFacet
  132. //------------------------------------------------------------------------------
  133.  
  134. CToolFacet::~CToolFacet()
  135. {
  136. }
  137.  
  138. //------------------------------------------------------------------------------
  139. // CToolFacet::Draw
  140. //------------------------------------------------------------------------------
  141.  
  142. void CToolFacet::Draw(FW_CGraphicContext *gc)
  143. {
  144. FW_UNUSED(gc);
  145.  
  146.     DrawTools(gc);
  147.     DrawColors(gc);
  148.     
  149.     FW_CColor black(FW_kRGBBlack);
  150.     ::RGBForeColor(&(RGBColor)black);        // temporary
  151.     
  152.     FW_CAcquireASLMResourceAccess aq;
  153.     
  154.     FW_SPlatformRect r;
  155.     PicHandle hPic = ::GetPicture(131);
  156.     ::SetRect(&r, 2, 2 + kToolHeight + 3, kToolWidth + 2, 2 + kToolHeight + 3 + kSelectorHeight);
  157.     ::DrawPicture(hPic, &r);
  158.     
  159.     DrawFillFrame(fDrawPart->GetFillFrame(), FW_kBlackPat);
  160. }
  161.  
  162. //------------------------------------------------------------------------------
  163. // CToolFacet::DrawTools
  164. //------------------------------------------------------------------------------
  165.  
  166. void CToolFacet::DrawTools(FW_CGraphicContext *gc)
  167. {
  168. FW_UNUSED(gc);
  169.  
  170.     FW_CAcquireASLMResourceAccess aq;
  171.     
  172.     FW_SPlatformRect r;
  173.     ::SetRect(&r, 2, 2, kToolWidth + 2, kToolHeight  + 2);
  174.     PicHandle hPic = ::GetPicture(128 + fDrawPart->GetFillFrame() - 1);
  175.     ::DrawPicture(hPic, &r);
  176.  
  177.     InvertTool(gc, fDrawPart->GetTool());
  178. }
  179.  
  180. //------------------------------------------------------------------------------
  181. // CToolFacet::DrawColors
  182. //------------------------------------------------------------------------------
  183.  
  184. void CToolFacet::DrawColors(FW_CGraphicContext *gc)
  185. {
  186.     XMPCoordinate left = 5;
  187.     XMPCoordinate top = kToolsWindowHeight - kColorSelectorHeight - 5;
  188.     FW_CRect colorRect(ff(left), ff(top), ff(left + kColorSelectorWidth), ff(top + kColorSelectorHeight));
  189.     
  190.     FW_CColor color;
  191.         
  192.     FW_CRectShape rectShape(colorRect);
  193.     
  194.     fDrawPart->GetFillColor(&color);
  195.     rectShape->SetForeColor(color);
  196.     rectShape->SetPenSize(ff(5));
  197.     rectShape->Draw(gc);            // fill
  198.     
  199.     fDrawPart->GetPenColor(&color);
  200.     rectShape->SetForeColor(color);    
  201.     rectShape->SetShapeFill(FW_kFramed);
  202.     rectShape->Draw(gc);            // frame
  203. }
  204.  
  205. //------------------------------------------------------------------------------
  206. // CToolFacet::DoMouseDown
  207. //------------------------------------------------------------------------------
  208.  
  209. FW_Boolean CToolFacet::DoMouseDown(const FW_CPoint& where, XMPEventData event)
  210. {
  211. FW_UNUSED(event);
  212.  
  213.     for (short i = 0; i < kNbRects; i++)
  214.     {
  215.         if (fRects[i].Contains(where))
  216.         {
  217.             if (i<=5)
  218.                 fDrawPart->SetTool(kSelectTool + i);
  219.             else
  220.                 fDrawPart->SetFillFrame(i-5);
  221.             return TRUE;
  222.         }
  223.     }
  224.  
  225.     return FALSE;
  226. }
  227.  
  228. //------------------------------------------------------------------------------
  229. // CToolFacet::CheckTool
  230. //------------------------------------------------------------------------------
  231.  
  232. void CToolFacet::CheckTool(unsigned short oldTool, unsigned short newTool)
  233. {
  234.     FW_CGraphicContext i(*this);
  235.     InvertTool(&i, oldTool);
  236.     InvertTool(&i, newTool);
  237. }
  238.  
  239. //------------------------------------------------------------------------------
  240. // CToolFacet::InvertTool
  241. //------------------------------------------------------------------------------
  242.  
  243. void CToolFacet::InvertTool(FW_CGraphicContext* gc, unsigned short theTool)
  244. {
  245. FW_UNUSED(gc);
  246.  
  247.     if (theTool>0)
  248.     {
  249.         FW_SPlatformRect rect;
  250.         fRects[theTool -1].AsPlatformRect(rect);
  251.         ::InsetRect(&rect, 1, 1);
  252.         ::InvertRect(&rect);
  253.     }
  254. }
  255.  
  256. //------------------------------------------------------------------------------
  257. // CToolFacet::CheckFillFrame
  258. //------------------------------------------------------------------------------
  259.  
  260. void CToolFacet::CheckFillFrame(unsigned short oldFillFrame, unsigned short newFillFrame)
  261. {
  262.     FW_CGraphicContext i(*this);
  263.     DrawFillFrame(oldFillFrame, FW_kWhitePat);
  264.     DrawFillFrame(newFillFrame, FW_kBlackPat);
  265.     DrawTools(&i);
  266. }
  267.  
  268. //------------------------------------------------------------------------------
  269. // CToolFacet::DrawFillFrame
  270. //------------------------------------------------------------------------------
  271.  
  272. void CToolFacet::DrawFillFrame(unsigned short fillFrame, const FW_CPattern& pattern)
  273. {
  274.     if (fillFrame>0)
  275.     {
  276.         FW_SPlatformRect rect;
  277.         fRects[5 + fillFrame].AsPlatformRect(rect);
  278.         ::InsetRect(&rect, 1, 1);
  279.         ::OffsetRect(&rect, 0, 2);
  280.         ::PenPat(pattern);
  281.         ::PenSize(2, 2);
  282.         ::MoveTo(rect.left, rect.bottom);
  283.         ::LineTo(rect.right - 2, rect.bottom);
  284.     }
  285. }
  286.  
  287. //------------------------------------------------------------------------------
  288. // CToolFacet::UpdateColors
  289. //------------------------------------------------------------------------------
  290.  
  291. void CToolFacet::UpdateColors()
  292. {
  293.     FW_CGraphicContext gc(*this);
  294.     
  295.     DrawColors(&gc);
  296. }
  297.